package com.weipai.springboot.module.controller;

import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: 曹朋飞
 * @Date: 2018/08/28 19:37
 * 
 * 评论控制类
 */
@RestController
public class EvaluateController {
    
    @Autowired
    EvaluateService evaluateService;

    /**
     * 分页查询
     * @param page 页码
     * @param size 每页条数
     */
    @GetMapping("/evaluate/list/{page}/{size}/{draw}")
    public Response list(@PathVariable("page") Integer page,
                         @PathVariable("size") Integer size,
                         @PathVariable("draw") String draw){
        return evaluateService.selectAllByPage(page, size, draw);
    }

    /**
     * 前端调用，某一货品的所有评论，分页查询
     * @param page 页码
     * @param size 每页条数
     * @param spuNumber 货品编号
     * @param judgeValue 是否只有图片的评价，1只看图，0正常
     */
    @GetMapping("/evaluate/list/{page}/{size}/{spuNumber}/{draw}/{judgeValue}")
    public Response getEvaluateBySpuNumber(@PathVariable("page") Integer page,
                         @PathVariable("size") Integer size,
                         @PathVariable("spuNumber") String spuNumber,
                         @PathVariable("draw") String draw,
                         @PathVariable("judgeValue") Integer judgeValue){
        return evaluateService.getEvaluateBySpuNumber(page, size, spuNumber, draw, judgeValue);
    }

    /**
     * 审核
     * @param id：评论的主键
     * @param status：审核状态
     * @return
     */
    @GetMapping("/evaluate/evaluateAudit/{evaluateId}/{status}")
    public Response evaluateAudit(@PathVariable("evaluateId") Integer id, @PathVariable("status") Integer status){
        return evaluateService.evaluateAudit(id, status);
    }

    /**
     * 回复评论
     * @param id：评论的主键
     * @param replyText：回复内容
     * @return
     */
    @PostMapping("/evaluate/replyEvaluate")
    public Response replyEvaluate(Integer id, String replyText){
        return evaluateService.replyEvaluate(id, replyText);
    }

    /**
     * 获取评论内容
     * @param id
     * @return
     */
    @GetMapping("/evaluate/getEvaluateInfo/{evaluateId}")
    public Response getEvaluateInfo(@PathVariable("evaluateId") Integer id){
        return evaluateService.getEvaluateInfo(id);
    }

    /**
     * 删除
     * @param id：评论的id
     * @return
     */
    @DeleteMapping("/evaluate/batchDeleteById/{id}")
    public Response batchDeleteById(@PathVariable("id")  String[] id){
        return evaluateService.batchDeleteById(id);
    }
    
    
}
